<template>
    <div id="navbarHeader">
        <div class="content">
            <div class="logo">
                <img src="" alt="LOGO">
            </div>
            <div class="nav">
                <div class="title">
                    后台管理
                </div>
                <div class="itembox">
                    <div class="item">
                        <el-link type="success">{{ user.name }}</el-link>
                    </div>
                    <div class="item">
                        <el-button type="primary" @click="logOut" >退出</el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                user: {}
            }
        },
        mounted () {
            this.getUserInfo();
        },
        methods: {
            // 获取用户信息
            async getUserInfo() {
                let res = await this.$axios.post("/users/getUserInfo")
                console.log(res);
                
                let code = res.data.code
                if (code == 200) {
                    this.user = res.data.data
                }
            },

            // 退出
            logOut() {
                localStorage.removeItem("token")
                this.$router.push("/login")
                this.$message.success("退出成功")
            },
        },
    }
</script>

<style lang="scss" scoped>
    #navbarHeader {
        width: 100%;
        height: 60px;
        line-height: 60px;
        position: fixed;
        left: 0; top: 0;
        z-index: 20;
        .content {
            width: 100%;
            display: flex;
            align-content: center;
            background-color: #000;
            color: #fff;
            .logo {
                width: 200px;
                overflow: hidden;
                img {
                    width: 200px;
                    height: 50px;
                }
            }
            .nav {
                flex: 1;
                display: flex;
                align-content: center;
                justify-content: space-between;
                padding-right: 20%;
                .itembox {
                    display: flex;
                    align-content: center;
                    .item {
                        margin: 0 10px;
                    }
                }
            }
        }
    }
</style>